<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>fold</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_001_014_757">&nbsp;</a>NAME</h4><blockquote>
fold - filter for folding lines
</blockquote><h4><a name = "tag_001_014_758">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

fold <b>[</b>-bs<b>][</b>-w <i>width</i><b>][</b><i>file</i>...<b>]
</b></code>
</pre>
</blockquote><h4><a name = "tag_001_014_759">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>fold</i>
utility is a filter that will fold lines from its input files,
breaking the lines to have a maximum of
<i>width</i>
column positions (or bytes, if the
<b>-b</b>
option is specified).
Lines will be broken by the insertion of a
newline
character such that each output line (referred to later in
this section as a segment) is the maximum width possible that does not
exceed the specified number of column positions (or bytes).
A line will not be broken in the middle of a character.
The behaviour is undefined if
<i>width</i>
is less than the number of columns any single character in the
input would occupy.
<p>
If the
carriage-return,
backspace
or
tab
characters are encountered in the input, and the
<b>-b</b>
option is not specified, they will be treated specially:
<dl compact>

<dt>backspace<dd>
The current count of line width will be decremented by
one, although the count never will become negative.
The
<i>fold</i>
utility will not insert a
newline character
immediately before or after any
backspace character.

<dt>carriage-return<dd>
The current count of line width will be set to zero.
The
<i>fold</i>
utility will not insert a
newline character
immediately before or after any
carriage-return character.

<dt>tab<dd>Each
tab
character encountered will advance the column position pointer
to the next tab stop.
Tab stops will be at each column position
<i>n</i>
such that
<i>n</i>
modulo 8 equals 1.

</dl>
</blockquote><h4><a name = "tag_001_014_760">&nbsp;</a>OPTIONS</h4><blockquote>
The
<i>fold</i>
utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b>&nbsp;</a> .
<p>
The following options are supported:
<dl compact>

<dt><b>-b</b>
<dd>Count
<i>width</i>
in bytes rather than column positions.

<dt><b>-s</b>
<dd>If a segment of a line contains a
blank character
within the first
<i>width</i>
column positions (or bytes), break the line after the last such
blank character
meeting the width constraints.
If there is no
blank character
meeting the requirements, the
<b>-s</b>
option will have no effect for that output segment of the input line.

<dt><b>-w&nbsp;</b><i>width</i>
<dd>
Specify the maximum line length, in column positions
(or bytes if
<b>-b</b>
is specified).
The results are unspecified if
<i>width</i>
is not a positive decimal number.
The default value is 80.

</dl>
</blockquote><h4><a name = "tag_001_014_761">&nbsp;</a>OPERANDS</h4><blockquote>
The following operand is supported:
<dl compact>

<dt><i>file</i><dd>A pathname of a text file to be folded.
If no
<i>file</i>
operands are specified,
the standard input will be used.

</dl>
</blockquote><h4><a name = "tag_001_014_762">&nbsp;</a>STDIN</h4><blockquote>
The standard input will be used only if no
<i>file</i>
operands are specified.
See the INPUT FILES section.
</blockquote><h4><a name = "tag_001_014_763">&nbsp;</a>INPUT FILES</h4><blockquote>
If the
<b>-b</b>
option is specified, the input files must be text
files except that the lines are not limited to
{LINE_MAX}
bytes in length.
If the
<b>-b</b>
option is not specified, the input files must be text files.
</blockquote><h4><a name = "tag_001_014_764">&nbsp;</a>ENVIRONMENT VARIABLES</h4><blockquote>
The following environment variables affect the execution of
<i>fold</i>:
<dl compact>

<dt><i>LANG</i><dd>Provide a default value for the internationalisation variables
that are unset or null.
If
<i>LANG</i>
is unset or null, the corresponding value from the
implementation-dependent default locale will be used.
If any of the internationalisation variables contains an invalid setting, the
utility will behave as if none of the variables had been defined.

<dt><i>LC_ALL</i><dd>
If set to a non-empty string value,
override the values of all the other internationalisation variables.

<dt><i>LC_CTYPE</i><dd>
Determine the
locale for the interpretation of sequences of bytes of text data as
characters (for example, single- as opposed to multi-byte characters
in arguments and input files),
and for the determination of the width in column positions
each character would occupy on a constant-width font output device.

<dt><i>LC_MESSAGES</i><dd>
Determine the locale that should be used to affect
the format and contents of diagnostic
messages written to standard error.

<dt><i>NLSPATH</i><dd>
Determine the location of message catalogues
for the processing of
<i>LC_MESSAGES .
</i>
</dl>
</blockquote><h4><a name = "tag_001_014_765">&nbsp;</a>ASYNCHRONOUS EVENTS</h4><blockquote>
Default.
</blockquote><h4><a name = "tag_001_014_766">&nbsp;</a>STDOUT</h4><blockquote>
The standard output will be a file
containing a sequence of characters whose
order will be preserved from the input files, possibly with inserted
newline
characters.
</blockquote><h4><a name = "tag_001_014_767">&nbsp;</a>STDERR</h4><blockquote>
Used only for diagnostic messages.
</blockquote><h4><a name = "tag_001_014_768">&nbsp;</a>OUTPUT FILES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_769">&nbsp;</a>EXTENDED DESCRIPTION</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_770">&nbsp;</a>EXIT STATUS</h4><blockquote>
The following exit values are returned:
<dl compact>

<dt>0<dd>All input files were processed successfully.

<dt>&gt;0<dd>An error occurred.

</dl>
</blockquote><h4><a name = "tag_001_014_771">&nbsp;</a>CONSEQUENCES OF ERRORS</h4><blockquote>
Default.
</blockquote><h4><a name = "tag_001_014_772">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
The
<i><a href="cut.html">cut</a></i>
and
<i>fold</i>
utilities can be used to create text files out of files
with arbitrary line lengths.
The
<i><a href="cut.html">cut</a></i>
utility should be used when the
number of lines (or records) needs to remain constant.
The
<i>fold</i>
utility should be used when the contents of
long lines need to be kept contiguous.
<p>
The
<i>fold</i>
utility is frequently used to send text files to printers
that truncate, rather than fold,
lines wider than the printer is able to print
(usually 80 or 132 column positions).
<br>
</blockquote><h4><a name = "tag_001_014_773">&nbsp;</a>EXAMPLES</h4><blockquote>
An example invocation that submits a file of possibly long lines to the
printer (under the assumption that the user knows the line width of
the printer to be assigned by
<i><a href="lp.html">lp</a></i>):
<pre>
<code>
fold -w 132 bigfile | lp
</code>
</pre>
</blockquote><h4><a name = "tag_001_014_774">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_775">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="cut.html">cut</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
